import {sys} from "cc";


/**
 * 平台工具类
 */
export class PlatformUtils {
    /**
     * 浏览器
     */
    public static isBrowser(): boolean {
        return sys.isBrowser;
    }

    /**
     * 移动端
     */
    public static isMobile(): boolean {
        return sys.isMobile;
    }


    /**
     * 原生
     */
    public static isNative(): boolean {
        return sys.isNative;
    }

    /**
     * 安卓
     */
    public static isAndroid(): boolean {
        return sys.isNative && sys.os == sys.OS.ANDROID;
    }

    /**
     * 苹果
     */
    public static isIOS(): boolean {
        return sys.isNative && sys.os == sys.OS.IOS;
    }

    /**
     * 微信 小游戏
     */
    public static isWxGame(): boolean {
        return sys.platform === sys.Platform.WECHAT_GAME;
    }

    /**
     * 抖音 小游戏
     */
    public static isDyGame(): boolean {
        return sys.platform === sys.Platform.BYTEDANCE_MINI_GAME;
    }

    /**
     * Telegram 小游戏
     */
    public static isTelegramGame(): boolean {
        // console.log('isTelegramGame', window['TelegramGameProxy']);
        return false;
    }

    /**
     * Telegram WebApp
     */
    public static isTelegramWebApp(): boolean {
        // console.log('isTelegramWebApp', window['Telegram']);
        if (window['Telegram'] == undefined) return false;
        if (window['Telegram'].WebApp == undefined) return false;
        if (window['Telegram'].WebApp.platform == undefined) return false;
        return window['Telegram'].WebApp.platform != 'unknown';
    }

    /**
     * Telegram平台
     */
    public static isTelegram(): boolean {
        return PlatformUtils.isTelegramWebApp();
    }
}
